import { combineReducers } from "redux";

import { reducer as plusOne } from "./counterPlusOne";
import { reducer as minusOne } from "./counterMinusOne";
import { reducer as reset } from "./counterReset";
import initialState from './initialState'

// export { reducer as counterPlusOne } from "./counterPlusOne";
// export { reducer as counterMinusOne } from "./counterMinusOne";
// export { reducer as counterReset } from "./counterReset";

// const reducerMap = {
//   counterPlusOne: plusOne,
//   counterMinusOne: minusOne,
//   counterReset: reset
// };

// export default combineReducers(reducerMap);
 

const reducers = [
  plusOne,
  minusOne,
  reset
];  

export default function reducer(state = initialState, action) {
  let newState;
  switch (action.type) {
    // Handle cross-topic actions here
    default:
      newState = state;
      break;
  }
  return reducers.reduce((state, reducer) => reducer(state, action), newState);
}

